﻿using System.IO;
using AdTech.Common.WPF;

namespace AdTech.Snap
{
    /// <summary>
    /// Defines a validation rule for validation directory paths.
    /// </summary>
    public class ValidPathRule : IValidationProvider
    {
        // Properties
        /// <summary>
        /// Gets the default error message.
        /// </summary>
        public string ErrorMessage { get { return "Invalid path."; } }

        // Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="AdTech.Snap.ValidPathRule"/> class.
        /// </summary>
        public ValidPathRule() { }

        // Methods
        /// <summary>
        /// Validates if the given string is a valid directory path.
        /// </summary>
        /// <param name="sender">The sender who triggered the validation.</param>
        /// <param name="attribute">The attribute information for the property to be validated.</param>
        /// <param name="value">The value to be validated.</param>
        /// <returns>True if the value is a valid directory path</returns>
        public bool Validate(object sender, ValidatorAttribute attribute, object value)
        {
            return Directory.Exists(value as string);
        }
    }

}
